package com.szxy.frontend.order.controller;

import com.szxy.frontend.order.service.OrderService;
import com.szxy.pojo.TbOrder;
import com.szxy.pojo.TbOrderItem;
import com.szxy.pojo.TbOrderShipping;
import com.szxy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther:zwer
 * @Date:2019/9/26 10:26
 * @Description:com.szxy.frontend.order.controller
 * @Version:1.0
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/insertOrder")
    public Result insertOrder(String orderItem, TbOrder tbOrder, TbOrderShipping tbOrderShipping){
        try {
            //System.out.println(orderItem);
            Result result = Result.formatObjectToList(orderItem, TbOrderItem.class);
            List<TbOrderItem> orderItemList = (List<TbOrderItem>) result.getData();
            return this.orderService.insertOrder(orderItemList, tbOrder, tbOrderShipping);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.build(500, "error");
    }

}
